package com.neusoft.elm.controller;

import com.neusoft.elm.po.Business;
import com.neusoft.elm.po.Cart;
import com.neusoft.elm.service.CartService;
import com.neusoft.elm.service.impl.CartServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author：ljz
 * @Date：2022/8/23 14:21
 * @Description:
 */
public class CartController {
    public Object saveCart(HttpServletRequest request) throws Exception {
        Cart cart = new Cart();
        cart.setFoodId(Integer.valueOf(request.getParameter("foodId")));
        cart.setBusinessId(Integer.valueOf(request.getParameter("businessId")));
        cart.setUserId(request.getParameter("userId"));
        CartService service = new CartServiceImpl();
        int result = service.saveCart(cart);
        return result;
    }

    public Object updateCart(HttpServletRequest request) throws Exception {
        Cart cart = new Cart();
        cart.setFoodId(Integer.valueOf(request.getParameter("foodId")));
        cart.setBusinessId(Integer.valueOf(request.getParameter("businessId")));
        cart.setUserId(request.getParameter("userId"));
        cart.setQuantity(Integer.valueOf(request.getParameter("quantity")));
        CartService service = new CartServiceImpl();
        int result = service.updateCart(cart);//复制的时候注意改这里！！！！
        return result;//成功返回1
    }

    public Object removeCart(HttpServletRequest request) throws Exception {
        Cart cart = new Cart();
        if (request.getParameter("foodId") != null)//注意这里，课件可能有误
            cart.setFoodId(Integer.valueOf(request.getParameter("foodId")));
        cart.setBusinessId(Integer.valueOf(request.getParameter("businessId")));
        cart.setUserId(request.getParameter("userId"));
        CartService service = new CartServiceImpl();
        int result = service.removeCart(cart);//复制的时候注意改这里！！！！
        return result;//成功返回1
    }

    public Object listCart(HttpServletRequest request) throws Exception {
        Cart cart = new Cart();
        if (request.getParameter("businessId") != null)
            cart.setBusinessId(Integer.valueOf(request.getParameter("businessId")));
        cart.setUserId(request.getParameter("userId"));
        CartService service = new CartServiceImpl();
        List<Cart> result = service.listCart(cart);//复制的时候注意改这里！！！！
        return result;//成功返回1
    }
}
